Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(EmbedContributionFlow): add channel messaging #10880

Merged
merged 1 commit into from
Dec 24, 2024

Conversation

Betree
Copy link
Member

@Betree Betree commented Dec 24, 2024

Resolve opencollective/opencollective#4341
Resolve opencollective/opencollective#7640

How to use it

After integrating the iframe in your page, simply add this snippet somewhere in your javascript:

window.addEventListener('message', event => {
  if (event.origin === 'https://opencollective.com') {
    console.log(event); // Handle event
  }
});

Message types

All messages have an event property (the type) and a size property, that gives the size of the iframe body when the event was emitted. You can listen for the following events:

  • initialized: the page gets mounted
  • resized: the page gets resized
  • stepChange: the step of the contribution flow changes
  • success: the contribution flow was successful. The payload contains the order object, like:
{
  order: {
    id: 1234,
    legacyId: 1234,
    status: 'PENDING',
    frequency: 'ONETIME',
    amount: { value: 1000, valueInCents: 100000, currency: 'USD' },
    platformTipAmount: { value: 100, valueInCents: 10000, currency: 'USD' },
    tier: { id: 1234 }, // `tier` can be null
    fromAccount: { id: 1234 },
    toAccount: { id: 1234 }
  }
}

Preview

image

Copy link

vercel bot commented Dec 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
opencollective-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 24, 2024 11:47am
opencollective-styleguide ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 24, 2024 11:47am

pages/embed/contribution-flow.tsx Dismissed Show dismissed Hide dismissed
@Betree Betree marked this pull request as ready for review December 24, 2024 12:14
Copy link
Contributor

@kewitz kewitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Works like a charm!

@Betree Betree merged commit 35e6951 into main Dec 24, 2024
20 checks passed
@Betree Betree deleted the feat/embed-contribution-channel-messaging branch December 24, 2024 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants